package com.example.fund.fundstocks;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.example.fund.BaseActivity;
import com.example.fund.util.FundUtil1;
import com.example.fund.util.FundUtil2;
import com.example.fund.util.StringUtil;
import com.example.fund.R;

import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.text.TextPaint;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;

public class FundStocks extends BaseActivity {
	
	private LinearLayout root;
	private TextView txtIndexStocks;
	private TextView txtFundType;
	private TextView txtIndexStocksNumber;
	private TextView txtFundTypeNumber;
	private TextView txtPosition;
	private TextView txtQuery;
	private List<String> indexList;
	private List<String> orderFiledList;
	private List<String> fundTypeList;
	//header
	private TextView txtQty;
	private TextView txtShare;
	private TextView txtDayRise;
	private TextView txtWeekRise;
	private TextView txtMonthRise;
	private TextView txtQRise;
	private TextView txtQ1Rise;
	private TextView txtQ2Rise;
	private TextView txtQ3Rise;
	private TextView txtQ4Rise;
	private TextView txtQ5Rise;
	private TextView txtQ6Rise;
	private TextView txtQ7Rise;
	private TextView txtQ8Rise;
	private TextView txtQ9Rise;
	private TextView txtQ10Rise;
	
	//自定义弹出选择框
	private PopupWindow popupWindow;
	private ListView popupList;
	
	//当前点击的TextView
	private TextView tv;
	private TextView numberTv;
	
	//表格ListView
	private List<Map<String, Object>> dataList;
	private int selection = 0;
	
	//基金阶段涨幅
	private static Map<String,FundStageRise> fundStageRiseMap = new HashMap<String,FundStageRise>();
	
	private MyHScrollView headSrcrollView;
	private ListView mListView1;
	private MyAdapter myAdapter;
	private RelativeLayout mHead;
	
	private TextView txtIndexStocksHoldings;//持仓合计
	
	private int bg1 = Color.rgb(5, 167, 247);
	private int bg2 = Color.rgb(233,244,251);

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
//		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置全屏
		setContentView(R.layout.fundstocks);
		
		root = (LinearLayout)findViewById(R.id.root);
    	root.setBackgroundColor(bg1);
    	LinearLayout layoutTop = (LinearLayout)findViewById(R.id.layoutTop);
    	layoutTop.setBackgroundColor(bg1);
    	
    	txtIndexStocks = (TextView) findViewById(R.id.txtIndexStocks);
    	txtIndexStocksNumber = (TextView) findViewById(R.id.txtIndexStocksNumber);
		txtFundType = (TextView) findViewById(R.id.txtFundType);
		txtFundTypeNumber = (TextView) findViewById(R.id.txtFundTypeNumber);
    	txtQuery = (TextView) findViewById(R.id.txtQuery);
    	txtPosition = (TextView) findViewById(R.id.txtPosition);
    	InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.hideSoftInputFromWindow(txtPosition.getWindowToken(),0);
        txtIndexStocksHoldings = (TextView) findViewById(R.id.txtIndexStocksHoldings);//持仓合计

		txtQty = (TextView) findViewById(R.id.txtQty);
		txtShare = (TextView) findViewById(R.id.txtShare);
        txtDayRise = (TextView) findViewById(R.id.txtDayRise);
        txtWeekRise = (TextView) findViewById(R.id.txtWeekRise);
        txtMonthRise = (TextView) findViewById(R.id.txtMonthRise);
        txtQRise = (TextView) findViewById(R.id.txtQRise);
        txtQ1Rise = (TextView) findViewById(R.id.txtQ1Rise);
        txtQ2Rise = (TextView) findViewById(R.id.txtQ2Rise);
        txtQ3Rise = (TextView) findViewById(R.id.txtQ3Rise);
        txtQ4Rise = (TextView) findViewById(R.id.txtQ4Rise);
        txtQ5Rise = (TextView) findViewById(R.id.txtQ5Rise);
        txtQ6Rise = (TextView) findViewById(R.id.txtQ6Rise);
        txtQ7Rise = (TextView) findViewById(R.id.txtQ7Rise);
        txtQ8Rise = (TextView) findViewById(R.id.txtQ8Rise);
        txtQ9Rise = (TextView) findViewById(R.id.txtQ9Rise);
        txtQ10Rise = (TextView) findViewById(R.id.txtQ10Rise);
        //数据
    	orderFiledList = new LinkedList<String>();
    	orderFiledList.add("1-持仓数量");
    	orderFiledList.add("2-持仓占比");

		fundTypeList = new LinkedList<String>();
        fundTypeList.add("0-基金类型");
		fundTypeList.add("1-指数型");
		fundTypeList.add("2-偏股型");
		fundTypeList.add("3-债券型");
    	
    	//初始化自定义下拉框
        View contentView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.popupwindow, null);  
        contentView.setBackgroundColor(bg2);  
        popupWindow = new PopupWindow(root, 500, 900);  
        popupWindow.setContentView(contentView); 
        popupList = (ListView) contentView.findViewById(R.id.popupList);
        popupList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        popupWindow.setFocusable(true);  
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(new ColorDrawable(0));
		
		mHead = (RelativeLayout) findViewById(R.id.head);
		mHead.setFocusable(true);
		mHead.setClickable(true);
		mHead.setBackgroundColor(Color.parseColor("#b2d235"));
		mHead.setOnTouchListener(new ListViewAndHeadViewTouchLinstener());

		mListView1 = (ListView) findViewById(R.id.listView1);
		mListView1.setOnTouchListener(new ListViewAndHeadViewTouchLinstener());
		
		headSrcrollView = (MyHScrollView) mHead.findViewById(R.id.horizontalScrollView1);
		
		initData();
		initListener();
		txtQuery_OnClickListener();
		mListView1.setSelection(selection);
	}

	
	/**
	 * 初始化数据
	 */
	private void initData() {
    	Bundle dataContext = this.getIntent().getExtras();
    	if(dataContext!=null)
    	{
    		if(dataContext.get("indexStocksNumber")!=null)
    		{
    			txtIndexStocksNumber.setText(dataContext.get("indexStocksNumber").toString());
    		}
    		if(dataContext.get("indexStocksText")!=null)
    		{
    			txtIndexStocks.setText(dataContext.get("indexStocksText").toString());
    		}
			if(dataContext.get("fundTypeNumber")!=null)
			{
				txtFundTypeNumber.setText(dataContext.get("fundTypeNumber").toString());
			}
			if(dataContext.get("fundTypeText")!=null)
			{
				txtFundType.setText(dataContext.get("fundTypeText").toString());
			}
    		if(dataContext.get("positionText")!=null)
    		{
    			txtPosition.setText(dataContext.get("positionText").toString());
    	    	InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
    	        imm.hideSoftInputFromWindow(txtPosition.getWindowToken(),0);
    		}
    		if(dataContext.get("selection")!=null)
    		{
    			selection=Integer.valueOf(dataContext.get("selection").toString());
    		}
    	}
	}

	/**
	 * 注册事件
	 */
	private void initListener() {
		//股票点击弹出下拉框
/*		txtStocks.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View arg0) 
			{
				String indexNumber = txtIndexStocksNumber.getText().toString();
				String indexNumber2 = txtIndexStocks2Number.getText().toString();
			//	stocksList = FundStocksUtil.getStocksList(indexNumber, indexNumber2);
			//	initPopWindow(txtStocksNumber,(TextView)arg0,stocksList.toArray());
			}
		});*/
/*		txtStocks.addTextChangedListener(new TextWatcher(){
			@Override
			public void afterTextChanged(Editable arg0) {
				txtLevel2.setText("二级分类");
				txtLevel2Number.setText("");
				txtLevel3.setText("三级分类");
				txtLevel3Number.setText("");
				txtLevel4.setText("四级分类");
				txtLevel4Number.setText("");
				txtIndexStocks.setText("指数");
				txtIndexStocksNumber.setText("");
			}
			@Override
			public void beforeTextChanged(CharSequence arg0, int arg1,int arg2, int arg3) {}
			@Override
			public void onTextChanged(CharSequence arg0, int arg1, int arg2,int arg3) {}
		});*/
		//指数1点击弹出下拉框
		txtIndexStocks.setOnClickListener(new OnClickListener() 
		{
			@Override
			public void onClick(View arg0) 
			{
				indexList = FundStocksUtil.getIndexList();
				Iterator<String> it = indexList.iterator();
				while(it.hasNext())
				{
					String index = it.next();
					if(index.contains("XAU")||index.contains("OIL")
							||index.contains("0000001")||index.contains("0000832")
							||index.contains("0000000"))
					{
						it.remove();
					}
				}
				initPopWindow(txtIndexStocksNumber,(TextView)arg0,indexList.toArray());
			}
		});
/*		txtIndexStocks.addTextChangedListener(new TextWatcher(){
			@Override
			public void afterTextChanged(Editable arg0) {
				txtLevel2.setText("二级分类");
				txtLevel2Number.setText("");
				txtLevel3.setText("三级分类");
				txtLevel3Number.setText("");
				txtLevel4.setText("四级分类");
				txtLevel4Number.setText("");
				txtStocks.setText("指数");
				txtStocksNumber.setText("");
			}
			@Override
			public void beforeTextChanged(CharSequence arg0, int arg1,int arg2, int arg3) {}
			@Override
			public void onTextChanged(CharSequence arg0, int arg1, int arg2,int arg3) {}
		});*/

		//基金类型字段点击弹出下拉框
		txtFundType.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View arg0)
			{
				initPopWindow(txtFundTypeNumber,(TextView)arg0,fundTypeList.toArray());
			}
		});
		
    	//下拉框选中事件
    	popupList.setOnItemClickListener(new OnItemClickListener() 
    	{
    		@Override
    		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) 
    		{
    			String text = ((TextView)arg1).getText().toString();
    			if(text.indexOf("-")>0)
    			{
    				String[] textArr = text.split("-");
    				if(textArr.length>=2)
    				{
    					numberTv.setText(textArr[0]);
    					tv.setText(textArr[1]);
    				}else{
    					numberTv.setText("");
    					tv.setText(text);
    				}
    			}else
    			{
    				numberTv.setText("");
    				tv.setText(text);
    			}
    			popupWindow.dismiss();
    		}
    	});
    	
    	//查询按钮点击事件
    	txtQuery.setOnClickListener(new OnClickListener() 
    	{
    		@Override
    		public void onClick(View arg0) 
    		{
    	//		FundStocksUtil.test(db);
    			txtQuery_OnClickListener();
    		}
    	});

    	//点击列表表头进行排序
    	OnClickListener sort_OnClickListener = new OnClickListener() {
			@Override
			public void onClick(View v) {
				sort_OnClick(v);
			}
		};
		txtQty.setOnClickListener(sort_OnClickListener);
		txtShare.setOnClickListener(sort_OnClickListener);
		txtDayRise.setOnClickListener(sort_OnClickListener);
		txtWeekRise.setOnClickListener(sort_OnClickListener);
		txtMonthRise.setOnClickListener(sort_OnClickListener);
		txtQRise.setOnClickListener(sort_OnClickListener);
		txtQ1Rise.setOnClickListener(sort_OnClickListener);
		txtQ2Rise.setOnClickListener(sort_OnClickListener);
		txtQ3Rise.setOnClickListener(sort_OnClickListener);
		txtQ4Rise.setOnClickListener(sort_OnClickListener);
		txtQ5Rise.setOnClickListener(sort_OnClickListener);
		txtQ6Rise.setOnClickListener(sort_OnClickListener);
		txtQ7Rise.setOnClickListener(sort_OnClickListener);
		txtQ8Rise.setOnClickListener(sort_OnClickListener);
		txtQ9Rise.setOnClickListener(sort_OnClickListener);
		txtQ10Rise.setOnClickListener(sort_OnClickListener);
	}

	/**
	 * 查询事件
	 * @param
	 */
	protected void txtQuery_OnClickListener() {
		final String indexNumber = txtIndexStocksNumber.getText().toString();
		String filterStr = txtPosition.getText().toString();
		String fundTypeNumber = txtFundTypeNumber.getText().toString();
		dataList = FundStocksUtil.getFundList(indexNumber, fundTypeNumber,filterStr);

		myAdapter = new MyAdapter(this, R.layout.fundstocks_list_header,dataList,indexNumber,headSrcrollView);
		mListView1.setAdapter(myAdapter);

		//合计
		String holdings = "";
		if(dataList!=null)
		{
			double q1 = 0;
			double q2 = 0;
			double q3 = 0;
			double q4 = 0;
			double q5 = 0;
			double q6 = 0;
			double q7 = 0;
			double q8 = 0;
			double q9 = 0;
			double q10 = 0;
			double q11 = 0;
			double q12 = 0;

//			double q121 = 0;

			for(int i=0,s=dataList.size();i<s;i++)
			{
				Map<String, Object> map = dataList.get(i);
				Object obj = map.get("qty");
				if(obj==null || obj.toString().length()==0)
				{
					continue;
				}
				String[] qtyArr = obj.toString().split("-");
				if(qtyArr.length!=12)
				{
					continue;
				}
				try {
					q1+=Double.valueOf(qtyArr[0]);
					q2+=Double.valueOf(qtyArr[1]);
					q3+=Double.valueOf(qtyArr[2]);
					q4+=Double.valueOf(qtyArr[3]);
					q5+=Double.valueOf(qtyArr[4]);
					q6+=Double.valueOf(qtyArr[5]);
					q7+=Double.valueOf(qtyArr[6]);
					q8+=Double.valueOf(qtyArr[7]);
					q9+=Double.valueOf(qtyArr[8]);
					q10+=Double.valueOf(qtyArr[9]);
					q11+=Double.valueOf(qtyArr[10]);
					q12+=Double.valueOf(qtyArr[11]);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

/*			if(q1!=0)
			{
				q121 = 100*(q12/q1);
			}*/

			String maxDate = FundStocksUtil.getFundStocksMaxDate();
			holdings = (int)q1+"-"+(int)q2+"-"+(int)q3+"-"+(int)q4+"-"+(int)q5+"-"+(int)q6+"-"+(int)q7+"-"+(int)q8+"-"+(int)q9+"-"+(int)q10+"-"+(int)q11+"-"+(int)q12;
			String s = "\n        ";
			if(!StringUtil.isNullOrEmpty(maxDate))
			{
				if(maxDate.contains("-03-"))
				{
					holdings = (int)q1+"-"+(int)q2+"-"+(int)q3+s+(int)q4+"-"+(int)q5+"-"+(int)q6+"-"+(int)q7+s+(int)q8+"-"+(int)q9+"-"+(int)q10+"-"+(int)q11+s+(int)q12;
				}
				else if(maxDate.contains("-06-"))
				{
					holdings = (int)q1+"-"+(int)q2+s+(int)q3+"-"+(int)q4+"-"+(int)q5+"-"+(int)q6+s+(int)q7+"-"+(int)q8+"-"+(int)q9+"-"+(int)q10+s+(int)q11+"-"+(int)q12;
				}
				else if(maxDate.contains("-09-"))
				{
					holdings = (int)q1+s+(int)q2+"-"+(int)q3+"-"+(int)q4+"-"+(int)q5+s+(int)q6+"-"+(int)q7+"-"+(int)q8+"-"+(int)q9+s+(int)q10+"-"+(int)q11+"-"+(int)q12;
				}
				else if(maxDate.contains("-12-"))
				{
					holdings = (int)q1+"-"+(int)q2+"-"+(int)q3+"-"+(int)q4+s+(int)q5+"-"+(int)q6+"-"+(int)q7+"-"+(int)q8+s+(int)q9+"-"+(int)q10+"-"+(int)q11+"-"+(int)q12;
				}
			}
		}

		fundStageRiseMap.clear();
		FundStageRise info = FundStocksUtil.getFundStageRise(indexNumber,indexNumber,false);
		fundStageRiseMap.put(indexNumber, info);
		String rise = "";
		if(info!=null)
		{
			rise = "日("+dealNull(info.getDayRise())+")-周("+dealNull(info.getWeekRise())+")-月("+dealNull(info.getMonthRise())+")-Q("+dealNull(info.getQ())+")"
					+"-Q1("+dealNull(info.getQ1())+")-Q2("+dealNull(info.getQ2())+")-Q3("+dealNull(info.getQ3())+")"
					+"-Q4("+dealNull(info.getQ4())+")-Q5("+dealNull(info.getQ5())+")-Q6("+dealNull(info.getQ6())+")"
					+"-Q7("+dealNull(info.getQ7())+")-Q8("+dealNull(info.getQ8())+")";
		}

		txtDayRise.setText("日"+dealNull(info.getDayRise())+"");
		txtDayRise.setTextColor(getNegativeAndPositiveColor(info.getDayRise()));
		txtWeekRise.setText("周"+dealNull(info.getWeekRise())+"");
		txtWeekRise.setTextColor(getNegativeAndPositiveColor(info.getWeekRise()));
		txtMonthRise.setText("月"+dealNull(info.getMonthRise())+"");
		txtMonthRise.setTextColor(getNegativeAndPositiveColor(info.getMonthRise()));
		txtQRise.setText(""+dealNull(info.getQ())+"("+dealNull(calRise(info.getQ1(),info.getQ()))+")");
		txtQRise.setTextColor(getNegativeAndPositiveColor(info.getQ()));
		txtQ1Rise.setText(""+dealNull(info.getQ1())+"("+dealNull(calRise(info.getQ2(),info.getQ1()))+")");
		txtQ1Rise.setTextColor(getNegativeAndPositiveColor(info.getQ1()));
		txtQ2Rise.setText(""+dealNull(info.getQ2())+"("+dealNull(calRise(info.getQ3(),info.getQ2()))+")");
		txtQ2Rise.setTextColor(getNegativeAndPositiveColor(info.getQ2()));
		txtQ3Rise.setText(""+dealNull(info.getQ3())+"("+dealNull(calRise(info.getQ4(),info.getQ3()))+")");
		txtQ3Rise.setTextColor(getNegativeAndPositiveColor(info.getQ3()));
		txtQ4Rise.setText(""+dealNull(info.getQ4())+"("+dealNull(calRise(info.getQ5(),info.getQ4()))+")");
		txtQ4Rise.setTextColor(getNegativeAndPositiveColor(info.getQ4()));
		txtQ5Rise.setText(""+dealNull(info.getQ5())+"("+dealNull(calRise(info.getQ6(),info.getQ5()))+")");
		txtQ5Rise.setTextColor(getNegativeAndPositiveColor(info.getQ5()));
		txtQ6Rise.setText(""+dealNull(info.getQ6())+"("+dealNull(calRise(info.getQ7(),info.getQ6()))+")");
		txtQ6Rise.setTextColor(getNegativeAndPositiveColor(info.getQ6()));
		txtQ7Rise.setText(""+dealNull(info.getQ7())+"("+dealNull(calRise(info.getQ8(),info.getQ7()))+")");
		txtQ7Rise.setTextColor(getNegativeAndPositiveColor(info.getQ7()));
		txtQ8Rise.setText(""+dealNull(info.getQ8())+"("+dealNull(calRise(info.getQ9(),info.getQ8()))+")");
		txtQ8Rise.setTextColor(getNegativeAndPositiveColor(info.getQ8()));
		txtQ9Rise.setText(""+dealNull(info.getQ9())+"("+dealNull(calRise(info.getQ10(),info.getQ9()))+")");
		txtQ9Rise.setTextColor(getNegativeAndPositiveColor(info.getQ9()));
		txtQ10Rise.setText(""+dealNull(info.getQ10())+"");
		txtQ10Rise.setTextColor(getNegativeAndPositiveColor(info.getQ10()));

		txtIndexStocksHoldings.setText("持仓:"+holdings);

		//新开一个线程加载前20行基金的阶段涨幅数据
		new Thread(new Runnable() {
			@Override
			public void run() {
				for(int i=0,s=Math.min(dataList.size()-1,19);i<=s;i++) {
					Map<String, Object> map = dataList.get(i);
					Object obj = map.get("number");
					if (obj == null || obj.toString().length() == 0) {
						continue;
					}
					String number = obj.toString();
					boolean isLast = (i==s);
					new LongTimeTaskForFundStageRise().execute(number,indexNumber,myAdapter,isLast);
				}
			}
		}).start();
	}

	/**
	 * 点击列表表头进行排序
	 * @param v
	 */
	protected void sort_OnClick(final View v)
	{
		Collections.sort(dataList,new Comparator<Map<String,Object>>(){
			@Override
			public int compare(Map<String,Object> o1, Map<String,Object> o2) {
				Object oNumber1 = o1.get("number");
				Object oNumber2 = o2.get("number");
				if (StringUtil.isNullOrEmpty(oNumber1) && StringUtil.isNullOrEmpty(oNumber2))
				{
					return 0;
				}
				if (!StringUtil.isNullOrEmpty(oNumber1) && StringUtil.isNullOrEmpty(oNumber2))
				{
					return -1;
				}
				if (StringUtil.isNullOrEmpty(oNumber1) && !StringUtil.isNullOrEmpty(oNumber2))
				{
					return 1;
				}
				String rise1 = "";
				String rise2 = "";
				if (v.equals(txtQty))
				{
					Object oQty1 = o1.get("qty");
					Object oQty2 = o2.get("qty");
					if(!StringUtil.isNullOrEmpty(oQty1) && oQty1.toString().indexOf("-")>0)
					{
						String str1 = oQty1.toString();
						rise1 = str1.substring(str1.lastIndexOf("-")+1);
					}
					if(!StringUtil.isNullOrEmpty(oQty2) && oQty2.toString().indexOf("-")>0)
					{
						String str2 = oQty2.toString();
						rise2 = str2.substring(str2.lastIndexOf("-")+1);
					}
				}else if (v.equals(txtShare))
				{
					Object oShare1 = o1.get("share");
					Object oShare2 = o2.get("share");
					if(!StringUtil.isNullOrEmpty(oShare1))
					{
						rise1 = oShare1.toString();
					}
					if(!StringUtil.isNullOrEmpty(oShare2))
					{
						rise2 = oShare2.toString();
					}
				}else {
					FundStageRise info1 = fundStageRiseMap.get(oNumber1.toString());
					FundStageRise info2 = fundStageRiseMap.get(oNumber2.toString());
					if (info1==null && info2==null)
					{
						return 0;
					}
					if (info1!=null && info2==null)
					{
						return -1;
					}
					if (info1==null && info2!=null)
					{
						return 1;
					}

					if (v.equals(txtDayRise))
					{
						rise1 = info1.getDayRise();
						rise2 = info2.getDayRise();
					}else if (v.equals(txtWeekRise))
					{
						rise1 = info1.getWeekRise();
						rise2 = info2.getWeekRise();
					}else if (v.equals(txtMonthRise))
					{
						rise1 = info1.getMonthRise();
						rise2 = info2.getMonthRise();
					}else if (v.equals(txtQRise))
					{
						rise1 = info1.getQ();
						rise2 = info2.getQ();
					}else if (v.equals(txtQ1Rise))
					{
						rise1 = info1.getQ1();
						rise2 = info2.getQ1();
					}else if (v.equals(txtQ2Rise))
					{
						rise1 = info1.getQ2();
						rise2 = info2.getQ2();
					}else if (v.equals(txtQ3Rise))
					{
						rise1 = info1.getQ3();
						rise2 = info2.getQ3();
					}else if (v.equals(txtQ4Rise))
					{
						rise1 = info1.getQ4();
						rise2 = info2.getQ4();
					}else if (v.equals(txtQ5Rise))
					{
						rise1 = info1.getQ5();
						rise2 = info2.getQ5();
					}else if (v.equals(txtQ6Rise))
					{
						rise1 = info1.getQ6();
						rise2 = info2.getQ6();
					}else if (v.equals(txtQ7Rise))
					{
						rise1 = info1.getQ7();
						rise2 = info2.getQ7();
					}else if (v.equals(txtQ8Rise))
					{
						rise1 = info1.getQ8();
						rise2 = info2.getQ8();
					}else if (v.equals(txtQ9Rise))
					{
						rise1 = info1.getQ9();
						rise2 = info2.getQ9();
					}
					else if (v.equals(txtQ10Rise))
					{
						rise1 = info1.getQ10();
						rise2 = info2.getQ10();
					}
				}

				if (StringUtil.isNullOrEmpty(rise1) && StringUtil.isNullOrEmpty(rise2))
				{
					return 0;
				}
				if (!StringUtil.isNullOrEmpty(rise1) && StringUtil.isNullOrEmpty(rise2))
				{
					return -1;
				}
				if (StringUtil.isNullOrEmpty(rise1) && !StringUtil.isNullOrEmpty(rise2))
				{
					return 1;
				}

				return (int)((Double.parseDouble(rise2)-Double.parseDouble(rise1))*100);
			}
		});
		myAdapter.notifyDataSetChanged();
	}

    /**
     * 设置返回值
     */
    private void setResult()
    {
    	Intent dataContext = this.getIntent();
    	dataContext.putExtra("indexStocksNumber", txtIndexStocksNumber.getText().toString());
    	dataContext.putExtra("indexStocksText", txtIndexStocks.getText().toString());
		dataContext.putExtra("fundTypeNumber", txtFundTypeNumber.getText().toString());
		dataContext.putExtra("fundTypeText", txtFundType.getText().toString());
    	dataContext.putExtra("positionText", txtPosition.getText().toString());
    	dataContext.putExtra("selection", selection);
    	if(dataList!=null && dataList.size()>0)
    	{
    		dataContext.putExtra("selectionNumber", dataList.get(selection).get("number")+"");
    		dataContext.putExtra("selectionName", dataList.get(selection).get("name")+"");
    	}else
    	{
    		dataContext.putExtra("selectionNumber", "");
    		dataContext.putExtra("selectionName", "");
    	}
    	
    	setResult(20, dataContext);
    }
	
    /**
     * 初始化弹出下拉框，
     * 适用范围：时间区间、涨幅、跌幅
     * @param view
     * @param objects
     */
	@SuppressWarnings("unchecked")
	private void initPopWindow(TextView numberView,TextView view,final Object[] objects){  
        ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, objects)
        {
        	@Override
        	public View getView(int position, View convertView, ViewGroup parent) {
        		TextView mTextView = new TextView(getApplicationContext());
                mTextView.setText(objects[position].toString());
                mTextView.setTextSize(15);
                mTextView.setTextColor(bg1);
                mTextView.setPadding(30, 10, 0, 10);
        		return mTextView;
        	}
        };  
        popupList.setAdapter(adapter);  
        String text = view.getText().toString();
        for(int i=0;i<objects.length;i++)
        {
        	if(objects[i]!=null && objects[i].toString().contains(text))
        	{
        		popupList.setSelection(i);
        		break;
        	}
        }
        popupWindow.showAsDropDown(view);
        tv = view;
        numberTv = numberView;
    }
	
    @Override
    protected void onResume() 
    {
    	if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)//横屏
    	{ 
   // 		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); 
    	}
    	super.onResume();
    }
    
    /**
     * 正负数字颜色
     * @param n
     * @return
     */
    private int getNegativeAndPositiveColor(String n)
    {
		if(!StringUtil.isNullOrEmpty(n))
		{
			if(Double.valueOf(n)>0)
			{
				return Color.RED;
			}else
			{
				return Color.GREEN;
			}
		}
		return Color.BLACK;
    }
    
	public static String calRise(String v1,String v2)
	{
		String vStr = null;
		if(!StringUtil.isNullOrEmpty(v1) && !StringUtil.isNullOrEmpty(v2) && new BigDecimal(v2).compareTo(BigDecimal.ZERO)!=0)
		{
			double d1 = Double.valueOf(v1);
			double d2 = Double.valueOf(v2);
			double d = (1.00d+d1/100.00d)*(1.00d+d2/100.00d);
			BigDecimal v = new BigDecimal(d);
			vStr = v.setScale(2,RoundingMode.HALF_UP).toString();
		}
		
		return vStr;
	}
	
	class ListViewAndHeadViewTouchLinstener implements View.OnTouchListener {

		@Override
		public boolean onTouch(View arg0, MotionEvent arg1) {
			//当在列头 和 listView控件上touch时，将这个touch的事件分发给 ScrollView
			headSrcrollView.onTouchEvent(arg1);
			return false;
		}
	}

	public class MyAdapter extends BaseAdapter {
		private List<HorizontalScrollView> mList = new ArrayList<HorizontalScrollView>();
        private List<Map<String,Object>> list;  
		private int id_row_layout;
		private LayoutInflater mInflater;
		private String indexNumber;
		
		private ViewHolder holder = null;

		public MyAdapter(Context context, int id_row_layout,List<Map<String,Object>> list,String indexNumber,MyHScrollView headSrcrollView) {
			super();
            this.list = list;
			this.id_row_layout = id_row_layout;
			mInflater = LayoutInflater.from(context);
			mList.add(headSrcrollView);
			this.indexNumber = indexNumber;
			headSrcrollView.setOnScrollChangedListener(mList);
		}

		@Override
		public int getCount() {
            int ret = 0;  
            if(list!=null){  
                ret = Math.min(100,list.size());
            }  
            return ret; 
		}

		@Override
		public Object getItem(int position) {
            return list.get(position);  
		}

		@Override
		public long getItemId(int position) {
            return position; 
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parentView) {
        	final Map<String,Object> info = (Map<String,Object>) this.getItem(position);  
            final int position1 = position; 
			if (convertView == null) {
				synchronized (FundStocks.this) {
					convertView = mInflater.inflate(id_row_layout, null);
					holder = new ViewHolder();

					MyHScrollView scrollView1 = (MyHScrollView) convertView.findViewById(R.id.horizontalScrollView1);

					holder.scrollView = scrollView1;
					holder.txtName = (TextView) convertView.findViewById(R.id.txtName);
	//				holder.txtNumber = (TextView) convertView.findViewById(R.id.txtNumber);
					holder.txtQty = (TextView) convertView.findViewById(R.id.txtQty);
					holder.txtShare = (TextView) convertView.findViewById(R.id.txtShare);
					holder.txtDayRise = (TextView) convertView.findViewById(R.id.txtDayRise);
					holder.txtWeekRise = (TextView) convertView.findViewById(R.id.txtWeekRise);
					holder.txtMonthRise = (TextView) convertView.findViewById(R.id.txtMonthRise);
					holder.txtQRise = (TextView) convertView.findViewById(R.id.txtQRise);
					holder.txtQ1Rise = (TextView) convertView.findViewById(R.id.txtQ1Rise);
					holder.txtQ2Rise = (TextView) convertView.findViewById(R.id.txtQ2Rise);
					holder.txtQ3Rise = (TextView) convertView.findViewById(R.id.txtQ3Rise);
					holder.txtQ4Rise = (TextView) convertView.findViewById(R.id.txtQ4Rise);
					holder.txtQ5Rise = (TextView) convertView.findViewById(R.id.txtQ5Rise);
					holder.txtQ6Rise = (TextView) convertView.findViewById(R.id.txtQ6Rise);
					holder.txtQ7Rise = (TextView) convertView.findViewById(R.id.txtQ7Rise);
					holder.txtQ8Rise = (TextView) convertView.findViewById(R.id.txtQ8Rise);
					holder.txtQ9Rise = (TextView) convertView.findViewById(R.id.txtQ9Rise);
					holder.txtQ10Rise = (TextView) convertView.findViewById(R.id.txtQ10Rise);
					holder.txtStocks = (TextView) convertView.findViewById(R.id.txtStocks);

	//				headSrcrollView.AddOnScrollChangedListener(scrollView1);
					
					mList.add(scrollView1);
					scrollView1.setOnScrollChangedListener(mList);
					convertView.setTag(holder);
				}
			} else {
				holder = (ViewHolder) convertView.getTag();
			}

			String number = String.valueOf(info.get("number"));
	//		holder.txtNumber.setText(number);
	//		holder.txtNumber.setTextSize(13);
	//		holder.txtNumber.setTextColor(Color.rgb(5, 167, 247));
            holder.txtName.setText(String.valueOf(info.get("name")));  
     //       holder.txtName.setTextSize(13);
   //         holder.txtName.setBackgroundColor(Color.parseColor("#b2d235"));
            holder.txtQty.setText(String.valueOf(info.get("qty")));  
    //        holder.txtQty.setTextSize(13);
            holder.txtShare.setText(String.valueOf(info.get("share")));  
    //        holder.txtShare.setTextSize(13);
			holder.txtStocks.setText(String.valueOf(info.get("stocks")));
			holder.txtStocks.setTextSize(10);
            
            //基金阶段涨幅
            if(fundStageRiseMap.containsKey(number))
            {
            	FundStageRise indexRise = fundStageRiseMap.get(indexNumber);
            	FundStageRise rise = fundStageRiseMap.get(number);
                holder.txtDayRise.setText(dealNull1(rise.getDayRise()));
                holder.txtWeekRise.setText(dealNull1(rise.getWeekRise()));
                holder.txtMonthRise.setText(dealNull1(rise.getMonthRise()));
                holder.txtQRise.setText(dealNull1(dealNull(rise.getQ())+"("+dealNull(calRise(rise.getQ1(),rise.getQ()))+")"));
                if(!StringUtil.isNullOrEmpty(indexRise.getQ10()) && indexRise.getQ10().contains("-"))
                {
                    holder.txtQ1Rise.setText(dealNull1(dealNull(rise.getQ1())+"("+dealNull(calRise(rise.getQ2(),rise.getQ1()))+")"));
                    holder.txtQ2Rise.setText(dealNull(rise.getQ2()));
                    holder.txtQ3Rise.setText(dealNull1(dealNull(rise.getQ3())+"("+dealNull(calRise(rise.getQ4(),rise.getQ3()))+")"));
                    holder.txtQ4Rise.setText(dealNull(rise.getQ4()));
                    holder.txtQ5Rise.setText(dealNull1(dealNull(rise.getQ5())+"("+dealNull(calRise(rise.getQ6(),rise.getQ5()))+")"));
                    holder.txtQ6Rise.setText(dealNull(rise.getQ6()));
                    holder.txtQ7Rise.setText(dealNull1(dealNull(rise.getQ7())+"("+dealNull(calRise(rise.getQ8(),rise.getQ7()))+")"));
                    holder.txtQ8Rise.setText(dealNull(rise.getQ8()));
                    holder.txtQ9Rise.setText(dealNull1(dealNull(rise.getQ9())+"("+dealNull(calRise(rise.getQ10(),rise.getQ9()))+")"));
                }else
                {
                    holder.txtQ1Rise.setText(dealNull(rise.getQ1()));
                    holder.txtQ2Rise.setText(dealNull1(dealNull(rise.getQ2())+"("+dealNull(calRise(rise.getQ3(),rise.getQ2()))+")"));
                    holder.txtQ3Rise.setText(dealNull(rise.getQ3()));
                    holder.txtQ4Rise.setText(dealNull1(dealNull(rise.getQ4())+"("+dealNull(calRise(rise.getQ5(),rise.getQ4()))+")"));
                    holder.txtQ5Rise.setText(dealNull(rise.getQ5()));
                    holder.txtQ6Rise.setText(dealNull1(dealNull(rise.getQ6())+"("+dealNull(calRise(rise.getQ7(),rise.getQ6()))+")"));
                    holder.txtQ7Rise.setText(dealNull(rise.getQ7()));
                    holder.txtQ8Rise.setText(dealNull1(dealNull(rise.getQ8())+"("+dealNull(calRise(rise.getQ9(),rise.getQ8()))+")"));
                    holder.txtQ9Rise.setText(dealNull(rise.getQ9()));
                }
                holder.txtQ10Rise.setText(dealNull(rise.getQ10()));
                
                if(indexRise!=null)
                {
                	setTextViewFont(holder.txtDayRise,rise.getDayRise(),indexRise.getDayRise());
                	setTextViewFont(holder.txtWeekRise,rise.getWeekRise(),indexRise.getWeekRise());
                	setTextViewFont(holder.txtMonthRise,rise.getMonthRise(),indexRise.getMonthRise());
                	setTextViewFont(holder.txtQRise,rise.getQ(),indexRise.getQ());
                	setTextViewFont(holder.txtQ1Rise,rise.getQ1(),indexRise.getQ1());
                	setTextViewFont(holder.txtQ2Rise,rise.getQ2(),indexRise.getQ2());
                	setTextViewFont(holder.txtQ3Rise,rise.getQ3(),indexRise.getQ3());
                	setTextViewFont(holder.txtQ4Rise,rise.getQ4(),indexRise.getQ4());
                	setTextViewFont(holder.txtQ5Rise,rise.getQ5(),indexRise.getQ5());
                	setTextViewFont(holder.txtQ6Rise,rise.getQ6(),indexRise.getQ6());
                	setTextViewFont(holder.txtQ7Rise,rise.getQ7(),indexRise.getQ7());
                	setTextViewFont(holder.txtQ8Rise,rise.getQ8(),indexRise.getQ8());
                	setTextViewFont(holder.txtQ9Rise,rise.getQ9(),indexRise.getQ9());
                	setTextViewFont(holder.txtQ10Rise,rise.getQ10(),indexRise.getQ10());
                }
            }else
            {
                holder.txtDayRise.setText(">");  
                holder.txtWeekRise.setText("");  
                holder.txtMonthRise.setText("");  
                holder.txtQRise.setText("");  
                holder.txtQ1Rise.setText("");  
                holder.txtQ2Rise.setText("");  
                holder.txtQ3Rise.setText("");  
                holder.txtQ4Rise.setText("");  
                holder.txtQ5Rise.setText("");  
                holder.txtQ6Rise.setText("");  
                holder.txtQ7Rise.setText("");  
                holder.txtQ8Rise.setText("");  
                holder.txtQ9Rise.setText("");  
                holder.txtQ10Rise.setText("");  
            }

			View.OnClickListener openFund_onClickListener = new View.OnClickListener() {

				@Override
				public void onClick(View view) {
					openFund_onClickFund(String.valueOf(info.get("number")));
				}
			};
  //          holder.txtNumber.setOnClickListener(openFund_onClickListener);
			holder.txtStocks.setOnClickListener(openFund_onClickListener);

            holder.txtName.setOnLongClickListener(new View.OnLongClickListener() { 
            	
				@Override
				public boolean onLongClick(View arg0) {
					fundName_onClickFund(position1,String.valueOf(info.get("number")),String.valueOf(info.get("name")));
					return false;
				} 
            });
            
            View.OnClickListener onClickListener = new View.OnClickListener() { 
            	
                @Override
                public void onClick(View view) { 
                    dayRise_onClickFund(String.valueOf(info.get("number")),indexNumber,MyAdapter.this);                  
                } 
            };
            
            holder.txtDayRise.setOnClickListener(onClickListener);
            holder.txtWeekRise.setOnClickListener(onClickListener);
            holder.txtMonthRise.setOnClickListener(onClickListener);
            holder.txtQRise.setOnClickListener(onClickListener);
            holder.txtQ1Rise.setOnClickListener(onClickListener);
            holder.txtQ2Rise.setOnClickListener(onClickListener);
            holder.txtQ3Rise.setOnClickListener(onClickListener);
            holder.txtQ4Rise.setOnClickListener(onClickListener);
            holder.txtQ5Rise.setOnClickListener(onClickListener);
            holder.txtQ6Rise.setOnClickListener(onClickListener);
            holder.txtQ7Rise.setOnClickListener(onClickListener);
            holder.txtQ8Rise.setOnClickListener(onClickListener);
            holder.txtQ9Rise.setOnClickListener(onClickListener);
            holder.txtQ10Rise.setOnClickListener(onClickListener);
            
			return convertView;
		}
		
		private int getRiseTextView(String rise1,String rise2)
		{
			if(!StringUtil.isNullOrEmpty(rise1) && !StringUtil.isNullOrEmpty(rise2))
			{
				if(Double.valueOf(rise1)>Double.valueOf(rise2))
				{
					return Color.RED;
				}else
				{
					return Color.GREEN;
				}
			}
			return Color.BLACK;
		}
		
		private void setTextViewFont(TextView view,String rise1,String rise2)
		{
			int color = Color.BLACK;
			boolean bold = false;
			int fontSize = 12;
			if(!StringUtil.isNullOrEmpty(rise1) && !StringUtil.isNullOrEmpty(rise2))
			{
				double r1 = Double.valueOf(rise1);
				double r2 = Double.valueOf(rise2);
				if(r1>r2)
				{
					color = Color.RED;
				}else if(r1<r2)
				{
					color = Color.rgb(0,199,140);
				}
				
/*				double ratio = (1+r1/100.00d)/(1+r2/100.00d);
				if(ratio>1.05d || ratio<0.95d)
				{
					bold = true;
					fontSize = 14;
				}*/
			}
			
			view.setTextColor(color);
			view.setTextSize(fontSize);
			TextPaint paint = view.getPaint(); 
			paint.setFakeBoldText(bold);
			
		}
		


		class ViewHolder {
			TextView txtName;
			TextView txtNumber;
			TextView txtQty;
			TextView txtShare;
			TextView txtDayRise;
			TextView txtWeekRise;
			TextView txtMonthRise;
			TextView txtThreeMonthRise;
			TextView txtSixMonthRise;
			TextView txtYearRise;
			TextView txtTwoYearRise;
			TextView txtQRise;
			TextView txtQ1Rise;
			TextView txtQ2Rise;
			TextView txtQ3Rise;
			TextView txtQ4Rise;
			TextView txtQ5Rise;
			TextView txtQ6Rise;
			TextView txtQ7Rise;
			TextView txtQ8Rise;
			TextView txtQ9Rise;
			TextView txtQ10Rise;
			TextView txtStocks;
			
			HorizontalScrollView scrollView;
		}
	}// end class my
	protected void openFund_onClickFund(String number)
    {
    	String hyperlink = "http://m.1234567.com.cn/3g/fund/fund,"+number+".shtml";//超链接
        Intent intent = new Intent();        
        intent.setAction("android.intent.action.VIEW");    
        Uri content_url = Uri.parse(hyperlink);   
        intent.setData(content_url);  
        this.startActivity(intent);
	}
	
	protected void fundCorrel_onClickFund(View view,String number,Map<String,Object> info) 
	{
		try {
			new LongTimeTask().execute(view,number,info);
		} catch (Exception e) {
			e.printStackTrace();
		}
	} 
	
	protected void dayRise_onClickFund(String number,String indexNumber,MyAdapter adapter) 
	{
		try {
			new LongTimeTaskForFundStageRise().execute(number,indexNumber,adapter,true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	protected void fundStdev_onClickFund(View view,String number,Map<String,Object> info) 
	{
		try {
			new LongTimeTaskForStdev().execute(view,number,info);
		} catch (Exception e) {
			e.printStackTrace();
		}
	} 
	
	protected void fundName_onClickFund(int position,String number,String name) 
    {
		selection = position;
		setResult();
		this.finish();
	}
	
	protected void fundTop3HYFL_onClickFund(String number,String name) 
    {
    	List<Map<String,Object>> data = FundStocksUtil.getFundStocksList(number);

    	SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.fundstockslistdialog,   
    			new String[]{"stocks","zzhyfl"}, new int[]{R.id.stocks,R.id.stocksfl});  

    	ListView listView = new ListView(this); 
    	listView.setAdapter(adapter);
    	
    	String date = "";
    	if(data!=null && data.get(0)!=null 
    			&& data.get(0).get("date")!=null)
    	{
    		date = data.get(0).get("date").toString();
    	}

    	new AlertDialog.Builder(this).setTitle(name+"10大持仓  截止"+date).setView(listView)
    	.setNegativeButton("关闭", null).show();
	}
	
    /**
     * 工作线程中操作UI线程内部类
     * 适用范围：
     * @author haohan
     *
     */
    private class LongTimeTask extends AsyncTask  
    {
    	private View view;
    	private String number;
    	private Map<String,Object> info;
    	private List<Map.Entry<String,Double>> mappingList;
    	/**
    	 * 更新UI的操作，这里面的内容是在UI线程里面执行的
    	 */
		@Override
		protected void onPostExecute(Object result) {
			super.onPostExecute(result);
			
			try {
				int i=0;
				String text = "";
				Map<String, String> indexNameMap = FundUtil1.getIndexNameMap();
				for(Map.Entry<String,Double> mapping:mappingList)
				{ 
					if(i==0)
					{
						text = indexNameMap.get(mapping.getKey())+"("+mapping.getValue()+")";
					}else if(i<3)
					{
						text = text+" "+indexNameMap.get(mapping.getKey())+"("+mapping.getValue()+")";
						
					}else
					{
						break;
					}
					i++;
				} 
				if(view instanceof TextView)
				{
					((TextView)view).setText(text);
					if(info!=null)
					{
						info.put("correl", text);
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		/**
		 * 耗时操作，这里面的内容Android系统会自动为你启动一个新的线程执
		 */
		@Override
		protected Object doInBackground(Object... arg0) {
			view = (View)arg0[0];
			number = arg0[1].toString();
			info = (Map<String,Object>)arg0[2];
			mappingList = FundUtil1.getCorrel(number);
			return null;
		}  
    }
    
    /**
     * 工作线程中操作UI线程内部类
     * 适用范围：
     * @author haohan
     *
     */
    private class LongTimeTaskForFundStageRise extends AsyncTask  
    {
    	private String number;
    	private String refNumber;
    	private MyAdapter adapter;
    	private boolean isLast;
    	/**
    	 * 更新UI的操作，这里面的内容是在UI线程里面执行的
    	 */
		@Override
		protected void onPostExecute(Object result) {
			super.onPostExecute(result);
			adapter.notifyDataSetChanged();
			if (isLast)
			{
				Toast.makeText(getApplicationContext(), "加载完成", Toast.LENGTH_SHORT).show();
			}
		}

		/**
		 * 耗时操作，这里面的内容Android系统会自动为你启动一个新的线程执
		 */
		@Override
		protected Object doInBackground(Object... arg0) {
			number = arg0[0].toString();
			refNumber = arg0[1].toString();
			adapter = (MyAdapter)arg0[2];
			isLast = (Boolean)arg0[3];
//			if(!fundStageRiseMap.containsKey(number))
//			{
				FundStageRise info = FundStocksUtil.getFundStageRise(number,refNumber,true);
				fundStageRiseMap.put(number, info);
//			}
			return null;
		}  
    }
    
    /**
     * 工作线程中操作UI线程内部类
     * 适用范围：
     * @author haohan
     *
     */
    private class LongTimeTaskForStdev extends AsyncTask  
    {
    	private View view;
    	private String number;
    	private Map<String,Object> info;
    	private List<Map.Entry<String,Double>> mappingList;
    	/**
    	 * 更新UI的操作，这里面的内容是在UI线程里面执行的
    	 */
		@Override
		protected void onPostExecute(Object result) {
			super.onPostExecute(result);
			
			try {
				int i=0;
				String text = "";
				Map<String, String> indexNameMap = FundUtil1.getIndexNameMap();
				for(Map.Entry<String,Double> mapping:mappingList)
				{ 
					if(i==0)
					{
						text = indexNameMap.get(mapping.getKey())+"("+mapping.getValue()+")";
					}else if(i<3)
					{
						text = text+" "+indexNameMap.get(mapping.getKey())+"("+mapping.getValue()+")";
						
					}else
					{
						break;
					}
					i++;
				} 
				if(view instanceof TextView)
				{
					((TextView)view).setText(text);
					if(info!=null)
					{
						info.put("stdev", text);
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

		/**
		 * 耗时操作，这里面的内容Android系统会自动为你启动一个新的线程执
		 */
		@Override
		protected Object doInBackground(Object... arg0) {
			view = (View)arg0[0];
			number = arg0[1].toString();
			info = (Map<String,Object>)arg0[2];
			mappingList = FundUtil2.getStdev(number);
			return null;
		}  
    }
    
    private String dealNull(Object obj)
    {
    	if(obj==null)
    	{
    		return "-";
    	}else
    	{
    		return obj.toString();
    	}
    }

	private String dealNull1(Object obj)
	{
		if(obj==null)
		{
			return "-";
		}else
		{
			String str = obj.toString();
			str = str.replaceAll("\\(","").replaceAll("\\)","").replaceAll("-","");
			if (str.trim().length()==0)
			{
				return "-";
			}
			return obj.toString();
		}
	}
}